const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getMyFeesEstimate = {};
getMyFeesEstimate.generateOption = function(seller_id, mws_auth_token, marketplaceId, feesEstimateRequestList){
  let baseOption = {
    'Version': '2011-10-01',
    'Action': 'GetMyFeesEstimate',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    // 'ASINList.ASIN.1': 'B07RP44QPT'
  };

  const option = Object.assign(baseOption, jsonflatten.flatten(feesEstimateRequestList, null, baseIndex=1));
  return option;
};

getMyFeesEstimate._ = function(options) {
  if (!isProduction) {
    return amazonMws.products.search(options);
  } else {
    console.error("bot not implemented!");
  }
};

getMyFeesEstimate.getMyFeesEstimate = function(seller_id, mws_auth_token, marketplaceId, feesEstimateRequestList) {
  return this._(this.generateOption(seller_id, mws_auth_token, marketplaceId, feesEstimateRequestList));
};

module.exports = getMyFeesEstimate;